@extends('back_end.layouts.default_info')
{{-- content_header --}}

@section('content_header')
控制台
@stop

{{-- breadcrumb --}}
@section('breadcrumb')
<li><a href="#"><i class="fa fa-dashboard"></i> 控制台</a></li>
@stop
{{-- Content --}}
@section('content')
<!-- Small boxes (Stat box) -->


<!-- Main row -->
<div class="row">

    <!-- Left col -->
    <section class="col-md-6 connectedSortable" id="section-left">
        <!-- today-send-list -->
        <div class="box box-danger order-today-send-list">
            <div class="box-header">
                <i class="fa fa-comment-o"></i>
                <h3 class="box-title">今日派送订单</h3>
                <div class="pull-right box-tools">
                    <button class="btn btn-danger btn-sm" data-widget='collapse' data-toggle="tooltip" title="Collapse"><i class="fa fa-minus"></i></button>
                    <button class="btn btn-danger btn-sm" data-widget='remove' data-toggle="tooltip" title="Remove"><i class="fa fa-times"></i></button>
                </div>
            </div><!-- /.box-header -->
            <div class="box-body">
                <ul class="todo-list">

                </ul>
            </div><!-- /.box-body -->
            <div class="box-footer clearfix no-border">
                <!--                <a href="{{{ URL::to('admin/ims') }}}" class="btn btn-default pull-right"><i class="fa fa-list"></i> {{{ Lang::get('general.more') }}}</a>-->
            </div>
        </div><!-- /.box -->

    </section><!-- /.Left col -->

    <!-- Left col -->
    <section class="col-lg-6 connectedSortable" id="section-right">
        <!-- today-get-list -->
        <div class="box box-danger order-today-get-list">
            <div class="box-header">
                <i class="fa fa-comment-o"></i>
                <h3 class="box-title">今日取餐订单</h3>
                <div class="pull-right box-tools">
                    <button class="btn btn-danger btn-sm" data-widget='collapse' data-toggle="tooltip" title="Collapse"><i class="fa fa-minus"></i></button>
                    <button class="btn btn-danger btn-sm" data-widget='remove' data-toggle="tooltip" title="Remove"><i class="fa fa-times"></i></button>
                </div>
            </div><!-- /.box-header -->
            <div class="box-body">
                <ul class="todo-list">

                </ul>
            </div><!-- /.box-body -->
            <div class="box-footer clearfix no-border">
                <!--                <a href="{{{ URL::to('admin/ims') }}}" class="btn btn-default pull-right"><i class="fa fa-list"></i> {{{ Lang::get('general.more') }}}</a>-->
            </div>
        </div><!-- /.box -->

    </section><!-- right col -->

</div><!-- /.row (main row) -->
@stop
{{-- Scripts --}}
@section('scripts')
<script type="text/javascript">

    $(function () {
        $(".connectedSortable").sortable({
            placeholder: "sort-highlight",
            connectWith: ".connectedSortable",
            handle: ".box-header",
            forcePlaceholderSize: true,
            zIndex: 999999
        }).disableSelection();

        $(".box-header").css("cursor","move");

        //配送与取餐
        var todaySendListUrl = '{{ URL::action("BackOrderController@getTodaySendList") }}';
        var todayGetListUrl  = '{{ URL::action("BackOrderController@getTodayGetList") }}';
        var todaySendListDom = $('.order-today-send-list .todo-list');
        var todayGetListDom  = $('.order-today-get-list .todo-list');

        setInterval(function(){
            refreshOrders();
        }, 60000);
        refreshOrders();

        function refreshOrders(){

            $.ajax({
                url: todaySendListUrl,
                type: 'GET',
                dataType : "json"
            }).done(function(data){
                    if(data.result){
                        todaySendListDom.children().remove();
                        for(var i=0;i< data.entries.length;i++){
                            todaySendListDom.append(getSendMealRow(data.entries[i]));
                        }
                    }
                });

            $.ajax({
                url: todayGetListUrl,
                type: 'GET',
                dataType : "json"
            }).done(function(data){
                    if(data.result){
                        todayGetListDom.children().remove();
                        for(var i=0;i< data.entries.length;i++){
                            todayGetListDom.append(getGetMealRow(data.entries[i]));
                        }
                    }
                });
        }

        function getSendMealRow(entry){
            return '\
                <li>\
                <small class="label label-danger"><i class="fa fa-clock-o"></i>预定时间:'+ entry.send_meal_time +'</small>\
                <span class="text">订单ID: '+ entry.id +'</span>\
                <div class="tools">\
                    <a href=""><i class="fa fa-edit"></i></a>\
                </div>\
                </li>\
            ';
        };

        function getGetMealRow(entry){
            return '\
                <li>\
                <small class="label label-danger"><i class="fa fa-clock-o"></i>预定时间:'+ entry.get_meal_time +'</small>\
                <span class="text">订单ID: '+ entry.id +'</span>\
                <div class="tools">\
                    <a href=""><i class="fa fa-edit"></i></a>\
                </div>\
                </li>\
            ';
        };
    });
</script>
@stop